package com.qiantu.phone.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.hjq.widget.layout.SettingBar;
import com.qiantu.phone.R;
import com.qiantu.phone.aop.Log;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.bean.TimeLimitBean;
import com.qiantu.phone.ui.dialog.BottomShareScopeDialog;
import com.qiantu.phone.ui.dialog.BottomTimeLimitDialog;
import com.lxj.xpopup.XPopup;

/**
 * time   : 2021/12/22
 */
public final class DeviceShareActivity extends AppActivity {

    @Log
    public static void start(Context context) {
        Intent intent = new Intent(context, DeviceShareActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }

    private SettingBar itemDeviceName;
    private SettingBar itemShareTimeLimit;
    private SettingBar itemShareScope;

    private BottomTimeLimitDialog mBottomTimeLimitDialog;
    private BottomShareScopeDialog mBottomShareScopeDialog;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_device_share;
    }

    @Override
    protected void initView() {
        itemDeviceName = findViewById(R.id.item_device_name);
        itemShareTimeLimit = findViewById(R.id.item_share_time_limit);
        itemShareScope = findViewById(R.id.item_share_scope);
        View itemMoments = findViewById(R.id.item_moments);
        itemMoments.setVisibility(View.GONE);
        setOnClickListener(R.id.item_device_name, R.id.item_share_time_limit, R.id.item_share_scope, R.id.item_wechat, R.id.item_copy_link);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onRightClick(View view) {
        DeviceShareRecordActivity.start(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.item_device_name:
                Intent intent = new Intent(this, SelectDeviceActivity.class);
                intent.putExtra("type", SelectDeviceActivity.TYPE_SELECT_DEVICE_SHARE);
                startActivity(intent);
                break;
            case R.id.item_share_time_limit:
                showBottomTimeLimitDialog();
                break;
            case R.id.item_share_scope:
                showBottomShareScopeDialog();
                break;
            case R.id.item_wechat:
                break;
            case R.id.item_copy_link:
                break;
        }
    }

    private void showBottomTimeLimitDialog(){
        if (mBottomTimeLimitDialog == null) {
            mBottomTimeLimitDialog = new BottomTimeLimitDialog(this);
            mBottomTimeLimitDialog.setDialogClickListener(new BottomTimeLimitDialog.DialogClickListener() {
                @Override
                public void onConfirmClick(TimeLimitBean timeLimitBean) {
                    itemShareTimeLimit.setRightText(timeLimitBean.getLabel());
                    mBottomTimeLimitDialog.dismiss();
                }
            });
            new XPopup.Builder(this)
                    .dismissOnBackPressed(true)
                    .enableDrag(true)
                    .asCustom(mBottomTimeLimitDialog);
        }
        mBottomTimeLimitDialog.show();
    }

    private void showBottomShareScopeDialog(){
        if (mBottomShareScopeDialog == null) {
            mBottomShareScopeDialog = new BottomShareScopeDialog(this);
            mBottomShareScopeDialog.setDialogClickListener(new BottomShareScopeDialog.DialogClickListener() {
                @Override
                public void onConfirmClick(int type, String phone) {
                    switch (type){
                        case 1:
                            itemShareScope.setRightText("公开");
                            break;
                        case 2:
                            itemShareScope.setRightText("指定 " + phone);
                            break;
                    }
                    mBottomShareScopeDialog.dismiss();
                }
            });
            new XPopup.Builder(this)
                    .dismissOnBackPressed(true)
                    .enableDrag(true)
                    .asCustom(mBottomShareScopeDialog);
        }
        mBottomShareScopeDialog.show();
    }

}